<template>
  <el-form-item
    :label="label"
    :label-width="labelWidth"
    :prop="props.data.field"
    :required="props.data.required"
    :rules="props.data.rules"
  >
    <el-input-number
      v-model="val"
      :style="{ width: `${props.data.compWidth || 100}%` }"
      :placeholder="props.data.placeholder"
      :min="props.data.min"
      :max="props.data.max"
      :precision="props.data.precision"
      :step="props.data.step"
      :controls="props.data.controls"
      :controls-position="props.data.controlsPosition"
      :readonly="props.data.readonly"
      :disabled="props.data.disabled"
      @change="onChange"
    />
  </el-form-item>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ElFormItem, ElInputNumber } from 'element-plus'
import { useProps } from '../../common-props/hooks'

const props = defineProps<{ data: Record<string, any>; form: Record<string, any> }>()
const emits = defineEmits(['valueChange'])

const { label, labelWidth } = useProps(props)
const val = ref()

const onChange = (value: any) => {
  emits('valueChange', { name: props.data.field, value })
}
</script>

<style lang="scss" scoped></style>
